package com.cisco.pso;

public class PsoFileItem extends FileItem{
	private String baseName;
	
	/**
	 * sub folder from psoxxxx/a/b/c
	 * e.g. a/b/c/
	 */
	private String subFolder;
	private int subFolderDepth=0;
	

	public PsoFileItem(String fullName, String shortName, String baseName) {
		super(fullName,shortName);
		
		//System.out.println(fullName);
		//parse module
		this.module = fullName.split("/")[2];
		
		this.baseName = baseName;
		
		//get sub folder
		String[] folders = fullName.split("/");
		
		int psoFolderIndex =-1;
		for(int i=folders.length-2;i>0;i--){
			if(folders[i].toLowerCase().startsWith("pso"))
			{
				psoFolderIndex=i;
				break;
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for(int i=psoFolderIndex+1;i<folders.length-1;i++)
		{
			sb.append(folders[i]+"/");
		}
		subFolder = sb.toString();
		subFolderDepth = folders.length - psoFolderIndex-2;
			
	}
	
	
	public String getBaseName() {
		return baseName;
	}

	public void setBaseName(String baseName) {
		this.baseName = baseName;
	}
 

	public String getSubFolder() {
		return subFolder;
	}

	public void setSubFolder(String subFolder) {
		this.subFolder = subFolder;
	}

	public int getSubFolderDepth() {
		return subFolderDepth;
	}

	public void setSubFolderDepth(int subFolderDepth) {
		this.subFolderDepth = subFolderDepth;
	}

	public static void main(String[] args) {
		String fullName = "pso/T28L/chemical/trainingcenter/src/java/com/webex/webapp/trainingcenter/psochemical/register/aa/CheRegisterHelper.java";
		String shortName ="CheRegisterHelper.java";
		String baseName ="RegisterHelper.java";
		
		PsoFileItem item = new PsoFileItem(fullName, shortName, baseName);
		System.out.println(item.getModule());
		System.out.println(item.getSubFolder());
		System.out.println(item.getSubFolderDepth());
	}

}
